/**
 * @file e5_t2_q5.c
 * @date 2022-03-09
 * 
 * @copyright Copyright (c) 2022 cnzyx MIT Licence
 * 
 */

#include<stdio.h>
#include<stdlib.h>
#define MAX 3

int diagSum(int array[][MAX]){
    int sum=0;
    for(int i=0,j=MAX-1;i<MAX;i++,j--){
        if(i!=j){
            sum+=array[i][i]+array[j][i];
        }else{
            sum+=array[i][i];
        }
    }
    return sum;
}

int main(int argc, char const *argv[])
{
    //UTF-8
    system("chcp 65001");

    int array[MAX][MAX],result;
    printf("请输入一个%dx%d的矩阵，两数之间以空格隔开：\n",MAX,MAX);
    for(int i=0;i<MAX*MAX;i++){
        scanf("%d",&array[i/MAX][i%MAX]);
    }
    result=diagSum(array);
    printf("对角线元素和为：%d\n",result);

    //Pause console
    system("pause");
    return 0;
}
